<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Article;
use app\common\model\Banner;
use app\common\model\Category;
use app\common\model\Order;
use app\common\model\Problem;
use app\common\model\Version;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function index()
    {
        $this->success('请求成功');
    }


    /**
     * Account:退款
     * User: Ixiangang
     * Date: 2025/2/24
     * Time: 14:31
     */
    public function tuik()
    {
        $order_no = $this->request->param('order_no');
        $money = $this->request->param('money');
        $pay_type = $this->request->param('pay_type');
        $rs = refundOrder($order_no, $pay_type, $money, $com = "退款");
        var_dump($rs);
        exit;
    }

    
    public function version()
    {
        $type = $this->request->param('type'); //android=安卓,ios=IOS
        $edition_number = $this->request->param('edition_number');
        if (!$type && !$edition_number) {
            $this->error('参数错误');
        }
        $version = Version::where('status', 'normal')->where('type', $type)->where('oldversion', '>=', $edition_number)->find();
        $this->success('ok', $version);
    }

    public function demo()
    {
        # 结束订单测试
        $demo = (new Order())->orderEndChatSessions(36);
        var_dump($demo);
        exit;
//        # 合伙人分佣测试
//        $demo = \app\common\model\Copartner::money(10, 3, 20, "分佣");
//        var_dump($demo);
    }




    /**
     * Account:首页分类
     * User: Ixiangang
     * Date: 2025/1/13
     * Time: 10:57
     */
    public function category()
    {
        $order = ['weigh' => 'asc'];
        $field = "id,name,image";
        $list = Category::where('status', 'normal')->field($field)->order($order)->select();
        $this->success(__('OK'), $list);
    }

    /**
     * Account:轮播图
     * User: Ixiangang
     * Date: 2025/1/2
     * Time: 10:48
     */
    public function banner()
    {
        $status = $this->request->param('status'); //分类:1=首页,2=金刚区
        if (!in_array($status, [1, 2])) {
            $this->error("参数错误");
        }
        $list = Banner::where('status', $status)->order('weigh asc')->select();
        $this->success(__("OK"), $list);
    }


    /**
     * Account:系统通知管理
     * User: Ixiangang
     * Date: 2025/2/6
     * Time: 10:04
     */
    public function article()
    {
        $list = Article::where('deletetime IS NULL')->field('id,title,brief,createtime,admin')->order('weigh asc')->select();
        $this->success(__('OK'), $list);
    }


    /**
     * Account:文本详情
     * User: Ixiangang
     * Date: 2025/2/19
     * Time: 16:50
     */
    public function articleDetails()
    {
        $info = Article::where('deletetime IS NULL')->field('id,title,brief,content,createtime,admin')->find($this->request->param('id'));
        $this->success(__('OK'), $info);
    }


    /**
     * Account:常见问题
     * User: Ixiangang
     * Date: 2025/2/13
     * Time: 15:24
     */
    public function problem()
    {
        $id = $this->request->param('id');
        if ($id) {
            $problem = Problem::find($id);
            $list = Problem::order('weigh asc')->select();
            $this->success(__('OK'), $problem);
        } else {
            $list = Problem::order('weigh asc')->select();
            $this->success(__('OK'), $list);
        }
    }

    /**
     * Account:协议内容
     * User: Ixiangang
     * Date: 2025/2/13
     * Time: 15:42
     */
    public function agreement()
    {
        $data = [
            'policy' => config('site.policy'), //隐私政策
            'protocol' => config('site.protocol'), //隐私协议
            'user_mobile' => config('site.user_mobile'), //用户客服电话
            'consultant_mobile' => config('site.consultant_mobile'),//咨询师客服电话
            'informed' => config('site.informed'),//知情同意书
            'carpooling_agreement' => config('site.carpooling_agreement'), //申请咨询师协议
            'consultant_agreement' => config('site.consultant_agreement'), //咨询师入驻协议
            'user_complaint' => config('site.user_complaint'), //投诉举报
        ];
        $this->success(__('OK'), $data);
    }

}
